<template>
  <div class="app-container">
    <div v-for="(item, i) in list" :key="item.uid">
      <div v-if="item.questionType === '单选'" class="list-item">
        <div class="title">{{ (i + 1) + '.' + item.questionName }}
          (<span class="questionType">{{ item.questionType }}</span>)</div>
        <el-radio-group v-model="item.result" class="options">
          <el-radio v-for="ele in item.questionOptions" :key="ele.options" :label="ele.value">
            {{ ele.value }}
          </el-radio>
        </el-radio-group>
      </div>
      <div v-else-if="item.questionType === '多选'" class="list-item">
        <div class="title">{{ (i + 1) + '.' + item.questionName }}
          (<span class="questionType">{{ item.questionType }}</span>)</div>
        <el-checkbox-group v-model="item.result" class="options">
          <el-checkbox v-for="ele in item.questionOptions" :key="ele.options" :label="ele.value">
            {{ ele.value }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
      <div v-else class="list-item">
        <div class="title">{{ (i + 1) + '.' + item.questionName }}
          (<span class="questionType">{{ item.questionType }}</span>)</div>
        <el-input style="margin-top: 20px;" v-model="item.result" placeholder="请输入"></el-input>
      </div>
    </div>
    <div style="display: flex;justify-content: center;">
      <el-button @click="submit()" type="primary">提交</el-button>
    </div>
  </div>
</template>

<script>
import * as orderManagement from '@/api/orderManagement'

export default {
  props: {
    uid: {
      type: String
    }
  },
  data () {
    return {
      list: null,
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList () {
      let param = {
        evaluationUid: this.uid
      }
      orderManagement.queryEvaluationUid(param).then(response => {
        this.list = response.data.rows || []
        if (this.list.length > 0) {
          this.list.map(item => {
            if (item.questionType === '单选') {
              item.questionOptions = JSON.parse(item.questionOptions)
            }
            if (item.questionType === '多选') {
              item.questionOptions = JSON.parse(item.questionOptions)
              this.$set(item, 'result', [])
            }
          })
        }

      }).catch(error => {

        console.log(error)
      })
    },
    submit () {
      console.log(this.list)
      this.$emit('close', this.list)
    },
    close () {
      this.$emit('close', '')
    }
  }
}
</script>
<style scoped lang="scss">
.list-item {
  width: 100%;
  padding: 20px;

  .title {
    font-size: 20px;
    font-weight: bold;

    .questionType {
      font-size: 18px;
      font-weight: normal;
    }
  }
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  margin-top: 20px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 10px;
}
</style>
